﻿//hot_news热点新闻模块交互
$.ajax({
	type:'GET',
	url:'/citrusmonitor/citrus.do?method=getCitruses&pageSize=4',
	dataType:'JSON',
	success:function(res){
		var hot_news_ul = document.getElementsByClassName("hot_news_ul")[0];
		var html = '';
		$.each(res.data,function(i,n){
//			if(i>=4){
//				return false;
//			}
			html += '<li class="hot_news_li"><a href="message.html?ci=33&id=" class="link"><img src="'+n["filePath"]+'"><span>'+n["citrusName"]+'</span></a></li>';
		});
		hot_news_ul.innerHTML=html;
	},
	error:function(){
		alert("资源加载失败！");
	}
});

//plant种植技术模块交互(柑橘种类)
function getCitrusType(){
	$.ajax({
		type:'GET',
		url:'/citrusmonitor/citrus.do?method=getCitruses&pageSize=5',
		dataType:'JSON',
		success:function(res){
			var citrus_type = document.getElementsByClassName("plant_ul")[0];
			var html_type = '';
			$.each(res.data,function(i,n){
				var summary = n["citrusName"] + "：" + n["period"];
				if(summary.length>=15){
					summary = summary.substring(0, 16) + "......";
				}
				html_type += '<li class="plant_ul_li"><a href="message.html?ci=33&id='+n["citrusId"]+'" class="li_link"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+summary+'</span><span>'+n["createTime"]+'</span></a></li>';
			});
			citrus_type.innerHTML = html_type;
		},
		error:function(){
			alert("柑橘种类资源加载失败！");
		}
	});
	
}
getCitrusType();//默认加载种植技术（柑橘种类）
//种植技术模块(种植方法)
function getplantMethod(){//调用再加载

	$.ajax({
			type:'POST',
			url:'/citrusmonitor/technology.do?method=getTechnologys',
			data: {
				'pageSize': 5,	
				'category': '种植技术'
			},
			dataType:'JSON',
			success:function(res){
				var plant_method = document.getElementsByClassName("plant_ul")[0];
				if(res.status == 1){
					var html_plant_method = '';
					$.each(res.data,function(i,n){
						if(n["title"].length>=15){
							n["title"] = n["title"].substring(0, 16) + "......";
						}
						html_plant_method += '<li class="plant_ul_li"><a href="message.html?ci=44&id='+n["technologyId"]+'" class="li_link"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+n["title"]+'</span><span>'+n["publishTime"]+'</span></a></li>';		
					});
					plant_method.innerHTML = html_plant_method;
				}
				
			},
			error:function(){
				alert("种植技术资源加载失败！");
			}
		});
}

//施肥技术，施药技术交互
(function(){
	
	$.ajax({
		type:'POST',
		url:'/citrusmonitor/technology.do?method=getTechnologys',
		data: {
			'pageSize': 6,	
			'category': '施肥技术'
		},
		dataType:'JSON',
		success:function(res){
			var fer_ul = document.getElementsByClassName("fer_ul")[0];
			if(res.status == 1){
				var html_fer = '';
				$.each(res.data,function(i,n){
					if(n["title"].length>=15){
						n["title"] = n["title"].substring(0, 16) + "......";;
					}
					html_fer += '<li class="plant_ul_li"><a href="message.html?ci=55&id='+n["technologyId"]+'" class="li_link"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+n["title"]+'</span><span>'+n["publishTime"]+'</span></a></li>';
				});
				fer_ul.innerHTML = html_fer;
			}
		},
		error:function(){
			alert("施肥技术资源加载失败！");
		}
	});
	$.ajax({
		type:'POST',
		url:'/citrusmonitor/technology.do?method=getTechnologys',
		data: {
			'pageSize': 6,	
			'category': '施药技术'
		},
		dataType:'JSON',
		success:function(res){
			var medicine_ul = document.getElementsByClassName("medicine_ul")[0];
			if(res.status == 1){
				var html_medicine = '';
				$.each(res.data,function(i,n){
					if(n["title"].length>=15){
						n["title"] = n["title"].substring(0, 16) + "......";
					}
					html_medicine += '<li class="plant_ul_li"><a href="message.html?ci=66&id='+n["technologyId"]+'" class="li_link"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+n["title"]+'</span><span>'+n["publishTime"]+'</span></a></li>';
				});
				medicine_ul.innerHTML = html_medicine;
			}
		},
		error:function(){
			alert("施肥技术资源加载失败！");
		}
	});
})();
		

//柑橘种类（图片）交互
$.ajax({
	type:'GET',
	url:'/citrusmonitor/citrus.do?method=getCitruses&pageSize=10',
	dataType:'JSON',
	success:function(res){
		var content_3_image_ul = document.getElementsByClassName("content_3_image_ul")[0];
		if(res.status == 1){
			var html = '';
			$.each(res.data,function(i,n){
				html += '<li><a href="message.html?ci=33&id='+n["citrusId"]+'" class="li_link"><img src="'+n["filePath"]+'"><span>'+n["citrusName"]+'</span></a></li>';
			});
			content_3_image_ul.innerHTML = html;
		}
	},
	error:function(){
		alert("柑橘种类资源加载失败！！");
	}
});


//基础信息交互（虫害信息）
function getPestMess(){

	$.ajax({
		type:'POST',
		url:'/citrusmonitor/pest.do?method=recent&pageSize=5',
		dataType:'JSON',
		success:function(data){
			var base_mes_ul = document.getElementsByClassName("base_mes_ul")[0];
			var html_base = '';
			var index = 0;
			$.each(data,function(i,n){
				if(index>=5){
					return false;
				}
				index++;
				html_base += '<li class="base_mes_ul_li"><a href="message.html?ci=22&id='+n["id"]+'" class="li_link"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+n["title"]+'</span><span>'+n["time"]+'</span></a></li>';
			});
			base_mes_ul.innerHTML = html_base;
		},
		error:function(){
			alert("基础信息资源加载失败！！");
		}
	});
}
getPestMess();//默认加载基础信息交互（虫害信息）


//基础信息交互（病害信息）
function getDiseaseMess(){//调用再加载

	$.ajax({
		type:'POST',
		url:'/citrusmonitor/disease.do?method=recent&pageSize=5',
		dataType:'JSON',
		success:function(data){
			var base_mes_ul = document.getElementsByClassName("base_mes_ul")[0];
			var html = '';
			var index = 0;
			$.each(data,function(i,n){
				if(index>=5){
					return false;
				}
				index++;
				html += '<li class="base_mes_ul_li"><a href="message.html?ci=11&id='+n["id"]+'" class="li_link"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+n["title"]+'</span><span>'+n["time"]+'</span></a></li>';
			});
			base_mes_ul.innerHTML = html;
		},
		error:function(){
			alert("基础信息资源加载失败！！");
		}
	});
}
//基础信息交互（虫害防治）ci=??
function getPestPrevent(){//调用再加载
	$.ajax({
		type:'POST',
		url:'/citrusmonitor/technology.do?method=getTechnologys',//后台填充URL
		data: {
			'pageSize': 5,	
			'category': '防虫技术'
		},
		dataType:'JSON',
		success:function(res){
			var base_mes_ul = document.getElementsByClassName("base_mes_ul")[0];
			if(res.status == 1){
				var html = '';
				$.each(res.data,function(i,n){
					if(n["title"].length>=15){
						n["title"] = n["title"].substring(0, 16) + "......";
					}
					html += '<li class="base_mes_ul_li"><a href="message.html?ci=101&id='+n["technologyId"]+'" class="li_link"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+n["title"]+'</span><span>'+n["publishTime"]+'</span></a></li>';
				});
				base_mes_ul.innerHTML = html;
			}
		},
		error:function(){
			alert("基础信息资源加载失败！！");
		}
	});

}


function getDiseasePrevent(){//调用再加载
	$.ajax({
		type:'POST',
		url:'/citrusmonitor/technology.do?method=getTechnologys',//后台填充URL
		data: {
			'pageSize': 5,	
			'category': '防害技术'
		},
		dataType:'JSON',
		success:function(res){
			var base_mes_ul = document.getElementsByClassName("base_mes_ul")[0];
			if(res.status == 1){
				var html = '';
				$.each(res.data,function(i,n){
					if(n["title"].length>=15){
						n["title"] = n["title"].substring(0, 16) + "......";
					}
					html += '<li class="base_mes_ul_li"><a href="message.html?ci=101&id='+n["technologyId"]+'" class="li_link"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+n["title"]+'</span><span>'+n["publishTime"]+'</span></a></li>';
				});
				base_mes_ul.innerHTML = html;
			}
		},
		error:function(){
			alert("基础信息资源加载失败！！");
		}
	});

}









//政策法规
$.ajax({
	type:'GET',
	url:'/citrusmonitor/law.do?method=showPartly&pageSize=5',
	dataType:'JSON',
	success:function(data){
		var base_mes_ul = document.getElementsByClassName("law_ul")[0];
		var html = '';
		var index = 0;
		$.each(data,function(i,n){
			if(index>=5){
				return false;
			}
			index++;
			html += '<li class="law_ul_li"><a href="law.html?lawId='+n["lawId"]+'" class="li_link"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+n["tittle"]+'</span><span>'+n["publishTime"]+'</span></a></li>';
		});
		base_mes_ul.innerHTML = html;
	},
	error:function(){
		alert("基础信息资源加载失败！！");
	}
});



//专家会诊交互
$.ajax({
	type:'get',
	url:'/citrusmonitor/question.do?method=showQAll&pageSize=5',
	dataType:'json',
	success:function(data){
		var expert_ul = document.getElementsByClassName("expert_ul")[0];
		var html = '';
		$.each(data,function(i,n){
			if(n["status"]=="已回复"){//已回复，添加样式
				html += '<li class="expert_ul_li"><a href="show_ans_ques.html?questionId='+n["questionId"]+'"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+n["summary"]+'</span><span><em class="em_active">已回复</em></span></a></li>';	
			}else{
				html += '<li class="expert_ul_li"><a href="show_ans_ques.html?questionId='+n["questionId"]+'"><svg class="icon_link" aria-hidden="true"><use xlink:href="#icon-setup"></use></svg><span>'+n["summary"]+'</span><span><em class="em_unactive">未回复</em></span></a></li>';	
			}
		});
		expert_ul.innerHTML = html;
	},
	error:function(){
		alert("专家模块资源加载失败！！");
	}
});



//hot_news模块

var hot_news_prev = document.getElementsByClassName("hot_news_prev")[0];
var hot_news_next = document.getElementsByClassName("hot_news_next")[0];
var hot_news_ul = document.getElementsByClassName("hot_news_ul")[0];
var hot_news_btn = document.getElementsByClassName("hot_news_btn")[0];
var btn_item = document.getElementsByClassName("btn_item");
var img_index = 0;
hot_news_ul.style.left = "0px";
//点击pre按钮
hot_news_prev.onclick = function(){
	var old_left = parseInt(hot_news_ul.style.left);
	if(old_left>=0){	
		hot_news_ul.style.left = "-960px";
		img_index = 3;
		show_btn(img_index);
	}else{
		hot_news_ul.style.left = old_left + 320 + "px";
		img_index -= 1;
		show_btn(img_index);
	}
}
//点击next按钮
hot_news_next.onclick = next_image;
function next_image(){
	var old_left = parseInt(hot_news_ul.style.left);
	if(old_left<=-960){	
		hot_news_ul.style.left = "0px";
		img_index = 0;
		show_btn(img_index);
	}else{
		hot_news_ul.style.left = old_left- 320 +"px";
		img_index +=1;
		show_btn(img_index);
	}
}
//点击按钮
function pressBtn(){
	for(let i=0,len=btn_item.length;i<len;i++){
		btn_item[i].onclick = function(){
			hot_news_ul.style.left = -i * 320 + "px";
			img_index = i;
			show_btn(img_index);
		}
	}
}
pressBtn();

//显示按钮
function show_btn(num){
	for(let i=0,len=btn_item.length;i<len;i++){
		if(btn_item[i].classList.contains("btn_active")){
			btn_item[i].classList.remove("btn_active");
			break;
		}					
	}
	btn_item[num].classList.add("btn_active");
}
//自动下滑
var image_time = setInterval(next_image,2000);
//鼠标hover，停止动作
hot_news_ul.onmouseover = hot_news_prev.onmouseover = hot_news_next.onmouseover = hot_news_btn.onmouseover =function(){
	clearInterval(image_time);
}
hot_news_ul.onmouseout = hot_news_prev.onmouseout = hot_news_next.onmouseout = hot_news_btn.onmouseout =function(){
	image_time = setInterval(next_image,2000);
}

//plant种植方法模块
var plant_tab = document.getElementsByClassName("plant_tab")[0];
var plant_tab_item = plant_tab.getElementsByTagName("span");
var plant_ul = document.getElementsByClassName("plant_ul");
var plant_link = document.getElementById("plant_link");
for(let i=0,len=plant_tab_item.length;i<len;i++){
	plant_tab_item[i].onclick = function(){
		if(i==0){
			plant_link.href = "message_ul.html?ci=33";
			getCitrusType();
		}else{
			plant_link.href = "message_ul.html?ci=44";
			getplantMethod();
		}
		for(let j=0;j<len;j++){
			if(plant_tab_item[j].classList.contains("tab_active")){
				plant_tab_item[j].classList.remove("tab_active");
				break;
			}
		}
		plant_tab_item[i].classList.add("tab_active");

	}
}


//content_3柑橘种类模块
var content_3 = document.getElementsByClassName("content_3")[0];
var content_3_image_ul = document.getElementsByClassName("content_3_image_ul")[0];
content_3_image_ul.style.left = "0px";
var direction=true;

//图片流自动滑动
function content_3_move(){
	
	var old_left = parseInt(content_3_image_ul.style.left);
	if(old_left<=(-1000)){
		direction = false;
	}
	if(old_left>=0){
		direction=true;
	}
	if(direction){
		content_3_image_ul.style.left = old_left - 50 + "px";
	}else{
		content_3_image_ul.style.left = old_left + 50 + "px";
	}
	
}

var content_3_time = setInterval(content_3_move,500);
content_3_image_ul.onmouseover = function(){
	clearInterval(content_3_time);
}
content_3_image_ul.onmouseout = function(){
	content_3_time = setInterval(content_3_move,500);
}

//base_mess基础信息模块
var base_mes_tab = document.getElementsByClassName("base_mes_tab")[0];
var base_mes_tab_item = base_mes_tab.getElementsByTagName("span");
var base_mes_ul = document.getElementsByClassName("base_mes_ul");
var base_link = document.getElementById("base_link");
for(let i=0,len=base_mes_tab_item.length;i<len;i++){
 	base_mes_tab_item[i].onclick = function(){
 		switch(i){
 			case 0:base_link.href = "message_ul.html?ci=22";
 				   getPestMess();
 				   break;
 			case 1:base_link.href = "message_ul.html?ci=11";
 				   getDiseaseMess();
 				   break;
 			case 2:base_link.href = "message_ul.html?ci=101";
 				   getPestPrevent();
 				   break;
 			case 3:base_link.href = "message_ul.html?ci=102";
 				   getDiseasePrevent();
 				   break;
 		}
		for(let j=0;j<len;j++){
			if(base_mes_tab_item[j].classList.contains("tab_active")){
				base_mes_tab_item[j].classList.remove("tab_active");
				break;
			}
		}
		base_mes_tab_item[i].classList.add("tab_active");
	}
}